import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import('@/views/home'),
    children: [
      {
        path: '/game',
        name: 'Game',
        component: () => import('@/views/game')
      },
      {
        path: '/contact',
        name: 'Contact',
        component: () => import('@/views/contact')
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/user')
  }
]

const router = new Router({
  mode: 'history',
  routes
})

router.beforeEach((to, from, next) => {
  next()
})

router.afterEach((to, from) => {
  document.documentElement.scrollTop = document.body.scrollTop = 0
  // 设置路由时间戳用于过渡效果
  if (!to.meta.timeStamp) { to.meta.timeStamp = Date.parse(new Date()) }
})

export default router
